package com.neusoft.resturant.controller;

import com.neusoft.resturant.common.utils.R;
import com.neusoft.resturant.entity.Student;
import com.neusoft.resturant.service.IStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: Daniel
 * @date: 2023-10-26 08:41
 **/
@RestController
@RequestMapping("/api/student")
public class StudentController {

    @Autowired
    private IStudentService studentService;

    /**
     * 查询学生信息列表
     */
    @GetMapping("/list")
    public R list(Student Student) {
        List<Student> list = studentService.selectStudentList(Student);
        return R.success(list);
    }


    /**
     * 获取学生信息详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id) {
        return R.success(studentService.selectStudentById(id));
    }

    /**
     * 新增学生信息
     */
    @PostMapping
    public R add(@RequestBody Student student) {
        int count = studentService.insertStudent(student);
        if (count > 0) {
            return R.success();
        }
        return R.error();
    }

    /**
     * 修改学生信息
     */
    @PutMapping
    public R edit(@RequestBody Student student) {
        return R.toAjax(studentService.updateStudent(student));
    }

    /**
     * 删除学生信息
     */
    @DeleteMapping("/{id}")
    public R remove(@PathVariable Long id)
    {
        return R.toAjax(studentService.deleteStudentById(id));
    }

}